home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / fortran / yaf77-1.1 / yaf77-1 / yaf77 / f77 next >
Encoding:
Text File  |  1996-01-29  |  9.2 KB  |  407 lines

  1. #!/bin/sh
  2. # Yaf77 - Yet another f77-style shell script to compile and load fortran, 
  3. # C, and assembly codes
  4.  
  5. PATH=/bin:/usr/bin:/usr/local/bin
  6. PROG=`basename $0`
  7. VERSION=Yaf77-1.1
  8.  
  9. CPP=${CPP:-/lib/cpp}
  10. F2C=${F2C:-/usr/bin/f2c}
  11. CC=${CC_f2c:-/usr/bin/gcc}
  12. AS=${AS:-/usr/bin/as} 
  13. CPPFLAGS=
  14. F2CFLAGS=${F2CFLAGS:='-ARw8 -Nn802'}
  15. CFLAGS=
  16. OPTBUGFLAG='-fno-strength-reduce'
  17. # HP:
  18. # OPTBUGFLAG=
  19. AFLAGS=
  20. LDFLAGS=
  21. LIBFLAGS=
  22. LIBF77EXT='-lF77ext'
  23. # Linux:
  24. F2CLIBS='-lf2c -lm'
  25. # HP:
  26. # F2CLIBS='-lF77 -lI77 -lm'
  27.  
  28. s=/tmp/stderr_$$
  29. t=/tmp/f77_$$
  30. rc=0
  31. cOPT=1
  32. trap "rm -f $s ; exit \$rc" 0
  33.  
  34. Yaf77Help()
  35. {
  36. cat << EOHELP
  37. usage:
  38.         yaf77 [-options ...] <files>
  39.  
  40. where options include:
  41.     -c                           no linking, leave relocatables
  42.     -o _file_                    place output in file _file_
  43.     -u                           make the default type of all variables
  44.                                    \`undefined'
  45.     -w                           suppress all warning messages
  46.     -w66                         suppress Fortran 66 compatibility warnings
  47.     -free                        assume free-format input
  48.     -C                           check that subscripts  are  within declared
  49.                                    array bounds
  50.     -N_t_nnn                     allow nnn entries in table _t_
  51.     -r8                          promote REAL to DOUBLE PRECISION, COMPLEX 
  52.                                    to DOUBLE COMPLEX
  53.     -bs|-fno-backslash           do not interpret backslash escapes in
  54.                                    character strings
  55.     -g                           add debugging symbols
  56.     -no-F77ext                   do not link against F77ext library
  57.     -I _dir_                     append directory _dir_ to  the list of
  58.                                    directories searched for include files;
  59.                                    affects both #include and INCLUDE statements
  60.     -D _macro_<=definition>      pass macro _macro_ to preprocessor
  61.     -U _macro_                   undefines macro _macro_
  62.     -B _prefix_                  add _prefix_ to search path of C compiler
  63.     -b _machine_                 compile for target _machine_
  64.     -aout                        for Linux dual aout/elf boxes, compile in aout
  65.                                    format; the same as \`-b i486-linuxaout'
  66.     -m386|-m486|-mpentium        make specific code optimizations for Intel 
  67.                                    processors
  68.     -ieee|-mieee-fp              make executables confirm to the IEEE floating  
  69.                                    point standards
  70.     -pipe                        use pipes instead of temporary files during
  71.                                    compilation (after f2c translation done)
  72.     -O0                          do not optimize (default)
  73.     -O|-O1|-O2|-O3               perform different levels of optimization
  74.     -S                           stop before assembling; leave assembler codes
  75.     -fpic                        generate position-independent code (for
  76.                                    dynamic linking)
  77.     -fPIC                        the same as above, even if branches need
  78.                                    large displacements
  79.     -l_library_                  use the library named _library_ when linking
  80.     -L _dir_                     add directory _dir_ to the list of directories
  81.                                    to be searched for \`-l'
  82.     -s                           strip executable
  83.     -static                      produce statically linked executables
  84.     -f2carg _arg_                pass argument _arg_ to f2c translator
  85.     -ccarg _arg_                 pass argument _arg_ to C compiler
  86.     -asarg _arg_                 pass argument _arg_ to assembler
  87.     -ldarg _arg_                 pass argument _arg_ to linker
  88.     -v                           verbose execution
  89.     -V                           print out version info and exit
  90.     -help                        print out this message
  91.     
  92. files:
  93.     *.f                          FORTRAN source files
  94.     *.F                          FORTRAN sources, to be preprocessed
  95.     *.[c,C]                      C/C++ source files
  96.     *.s                          Assembly language files
  97.     *.[o,a]                      Relocatables and ar archives
  98. EOHELP
  99. }
  100.  
  101. case $? in 0);; *) exit 1;; esac
  102. while
  103.     test X"$1" != X
  104. do
  105.     case "$1"
  106.     in
  107.     -c)    cOPT=0
  108.         shift
  109.         ;;
  110.  
  111.     -o)    OUTF="-o $2"
  112.         shift 2
  113.         ;;
  114.  
  115.     -D)    CPPFLAGS="$CPPFLAGS -D$2"
  116.         shift 2
  117.         ;;
  118.  
  119.     -D*)    CPPFLAGS="$CPPFLAGS $1"
  120.         shift
  121.         ;;
  122.  
  123.     -U)    CPPFLAGS="$CPPFLAGS -U$2"
  124.         shift 2
  125.         ;;
  126.  
  127.     -U*)    CPPFLAGS="$CPPFLAGS $1"
  128.         shift
  129.         ;;
  130.  
  131.     -I)    CPPFLAGS="$CPPFLAGS -I$2"
  132.             F2CFLAGS="$F2CFLAGS -I$2"
  133.         shift 2
  134.         ;;
  135.  
  136.     -I*)    CPPFLAGS="$CPPFLAGS $1"
  137.         F2CFLAGS="$F2CFLAGS $1"
  138.         shift
  139.         ;;
  140.  
  141.     -u)    F2CFLAGS="$F2CFLAGS -u"
  142.         shift
  143.         ;;
  144.  
  145.     -w)    F2CFLAGS="$F2CFLAGS -w"
  146.         shift
  147.         ;;
  148.  
  149.     -w66)   F2CFLAGS="$F2CFLAGS -w66"
  150.         shift
  151.         ;;
  152.  
  153.     -free)    F2CFLAGS="$F2CFLAGS -f"
  154.         shift
  155.         ;;
  156.  
  157.     -N)    F2CFLAGS="$F2CFLAGS $1""$2"
  158.         shift 2
  159.         ;;
  160.  
  161.     -N*)    F2CFLAGS="$F2CFLAGS $1"
  162.         shift 1
  163.         ;;
  164.  
  165.     -C)    F2CFLAGS="$F2CFLAGS $1"
  166.         shift 1
  167.         ;;
  168.  
  169.     -r8)    F2CFLAGS="$F2CFLAGS -r8"
  170.         shift
  171.         ;;
  172.  
  173.     -bs|-fno-backslash)
  174.             F2CFLAGS="$F2CFLAGS -!bs"
  175.         shift
  176.         ;;
  177.  
  178.     -g)    CFLAGS="$CFLAGS -g"
  179.         F2CFLAGS="$F2CFLAGS -g"
  180.         LDFLAGS="$LDFLAGS -g"
  181.         shift;;
  182.  
  183.     -B)    CFLAGS="$CFLAGS -B$2"
  184.         shift 2
  185.         ;;
  186.  
  187.     -B*)    CFLAGS="$CFLAGS $1"
  188.         shift
  189.         ;;
  190.  
  191.     -O0|-O|-O1)
  192.         CFLAGS="$CFLAGS $1"
  193.         shift
  194.         ;;
  195.  
  196.     -O2|-O3)
  197.         CFLAGS="$CFLAGS $1 $OPTBUGFLAG"
  198.         shift
  199.         ;;
  200.  
  201.     -pipe)  CFLAGS="$CFLAGS -pipe"
  202.         shift
  203.         ;;
  204.  
  205.     -m386|-m486|-mpentium)
  206.         CFLAGS="$CFLAGS $1"
  207.         shift
  208.         ;;
  209.  
  210.     -fPIC)  CFLAGS="$CFLAGS -fPIC"
  211.         shift
  212.         ;;
  213.  
  214.     -fpic)  CFLAGS="$CFLAGS -fpic"
  215.         shift
  216.         ;;
  217.  
  218.     -S)    CFLAGS="$CFLAGS -S"
  219.         cOPT=0
  220.         shift
  221.         ;;
  222.         
  223.     -b)     CFLAGS="$CFLAGS -b $2"
  224.             LDFLAGS="$LDFLAGS -b $2"
  225.         shift 2
  226.         ;;
  227.  
  228.     -b*)    CFLAGS="$CFLAGS $1"
  229.             LDFLAGS="$LDFLAGS $1"
  230.         shift
  231.         ;;
  232.  
  233.     -aout)  CFLAGS="$CFLAGS -b i486-linuxaout"
  234.             LDFLAGS="$LDFLAGS -b i486-linuxaout"
  235.         shift
  236.         ;;
  237.  
  238.     -ieee|-mieee-fp)
  239.             LDFLAGS="$LDFLAGS -mieee-fp"
  240.         shift
  241.         ;;
  242.  
  243.     -s)     LDFLAGS="$LDFLAGS -s"
  244.         shift
  245.         ;;
  246.  
  247.     -static) 
  248.             LDFLAGS="$LDFLAGS -static"
  249.         shift
  250.         ;;
  251.  
  252.     -L)     LIBFLAGS="$LIBFLAGS -L$2"
  253.         shift 2
  254.         case $cOPT in 1) cOPT=2;; esac
  255.         ;;
  256.  
  257.     -L*)    LIBFLAGS="$LIBFLAGS $1"
  258.         shift
  259.         case $cOPT in 1) cOPT=2;; esac
  260.         ;;
  261.  
  262.     -l)    LIBFLAGS="$LIBFLAGS -l$2"
  263.         shift 2
  264.         case $cOPT in 1) cOPT=2;; esac
  265.         ;;
  266.  
  267.         -l*)    LIBFLAGS="$LIBFLAGS $1"
  268.         shift
  269.         case $cOPT in 1) cOPT=2;; esac
  270.         ;;
  271.  
  272.     -f2carg)
  273.                 F2CFLAGS="$F2CFLAGS $2"
  274.         shift 2
  275.         ;;
  276.  
  277.     -ccarg) CFLAGS="$CFLAGS $2"
  278.         shift 2
  279.         ;;
  280.  
  281.     -asarg)
  282.         AFLAGS="$AFLAGS $2"
  283.         shift 2
  284.         ;;
  285.  
  286.         -ldarg) LDFLAGS="$LDFLAGS $2"
  287.         shift 2
  288.         ;;
  289.  
  290.     -no-F77ext)
  291.         LIBF77EXT=
  292.         shift 
  293.         ;;
  294.  
  295.     -v)     VERBOSE=1
  296.         shift 
  297.         ;;
  298.         
  299.     -V)     echo "$PROG: version $VERSION"
  300.         exit 
  301.         ;;
  302.  
  303.     -help)  Yaf77Help
  304.         exit 
  305.         ;;
  306.  
  307.     -*)     echo "$PROG: unrecognized option $1; -help lists all accepted options" 1>&2
  308.         shift
  309.         ;;
  310.  
  311.     *.[fFcCs])
  312.         SRCFILES="$SRCFILES $1"
  313.         shift
  314.         ;;
  315.  
  316.     *.[oa])
  317.         OFILES1="$OFILES1 $1"
  318.         case $cOPT in 1) cOPT=2;; esac
  319.         shift
  320.         ;;
  321.  
  322.     *)  echo "$PROG: don't know what to do with \`$1'" 1>&2
  323.         shift
  324.         ;;
  325.     esac
  326. done
  327.  
  328. INPFILES="$SRCFILES $OFILES1"
  329. LIBFLAGS="$LIBFLAGS $LIBF77EXT $F2CLIBS"
  330.  
  331. if [ $VERBOSE ]; then
  332.     echo "$PROG:"
  333.     echo "    f2c flags: " $F2CFLAGS
  334.     echo "    c flags: "$CFLAGS
  335.     echo "    as flags: "$CFLAGS
  336.     echo "    ld flags: "$LDFLAGS
  337.     echo "    libraries: "$LIBFLAGS
  338.     echo "    input files: "$INPFILES
  339. fi
  340.  
  341. if ( [ "$INPFILES" = " " ] ); then
  342.     echo "$PROG: No input files specified."
  343.     echo ""
  344.     exit
  345. fi
  346.  
  347. if [ $VERBOSE ]; then
  348.     echo "$PROG: Processing source files..."
  349. fi
  350.  
  351. for srcfile in $SRCFILES
  352. do
  353.     case "$srcfile"
  354.     in
  355.     *.[fF])
  356.                 case "$srcfile" in
  357.                         *.f)    b=`basename $srcfile .f`
  358.                                 $F2C $F2CFLAGS $srcfile
  359.                                 rc=$?
  360.                                 ;;
  361.                         *.F)    b=`basename $srcfile .F`
  362.                                 $CPP $CPPFLAGS $srcfile >$b.i
  363.                                 rc=$?
  364.                                 case $rc in 0)
  365.                                         $F2C $F2CFLAGS <$b.i >$b.c
  366.                                         rc=$?
  367.                                         ;;esac
  368.                                 rm $b.i
  369.                                 ;;
  370.                         esac
  371.                 case $rc in 0);; *) exit $rc;; esac
  372.                 case $cOPT in 0)OUTOF=$OUTF;; *);; esac
  373.                 $CC -c $CFLAGS $b.c $OUTOF 2>$s
  374.                 rc=$?
  375.                 sed '/parameter .* is not referenced/d;/warning: too many parameters/d' $s 1>&2
  376.                 case $rc in 0);; *) exit;; esac
  377.                 OFILES2="$OFILES2 $b.o"
  378.                 rm $b.c
  379.                 case $cOPT in 1) cOPT=2;; esac
  380.                 ;;
  381.     *.c)
  382.         echo $srcfile: 1>&2
  383.         OFILE=`basename $srcfile .c`.o
  384.                 $CC -c $CFLAGS $CPPFLAGS $srcfile
  385.         rc=$?; case $rc in 0);; *) exit;; esac
  386.         OFILES2="$OFILES2 $OFILE"
  387.         case $cOPT in 1) cOPT=2;; esac
  388.         ;;
  389.     *.s)
  390.         echo $srcfile: 1>&2
  391.         OFILE=`basename $srcfile .s`.o
  392.         $AS -o $OFILE $AFLAGS $srcfile
  393.         case $? in 0);; *) exit;; esac
  394.         OFILES2="$OFILES2 $OFILE"
  395.         case $cOPT in 1) cOPT=2;; esac
  396.         ;;
  397.     esac
  398. done
  399.  
  400. case $cOPT in 2) $CC $LDFLAGS $OUTF $OFILES1 $OFILES2 $LIBFLAGS 
  401.          case $? in 0) rm -f $OFILES2 ;; esac
  402.          ;; 
  403. esac
  404.  
  405. rc=$?
  406. exit $rc
  407.